import 'package:flutter/material.dart';

import 'package:velocity_x/velocity_x.dart';

import 'my_theme.dart';

class GradientButton extends StatelessWidget {
  VoidCallback onPressed;
  String text = '';
  bool disabled = false;
  double height = 46;

  getBoxDecoration() {
    if (disabled) {
      return BoxDecoration(
        borderRadius: BorderRadius.circular(height / 2),
        color: MyTheme.inputDisabledBackgroundColor,
        border: null,
      );
    } else {
      return BoxDecoration(
          borderRadius: BorderRadius.circular(height / 2),
          border: null,
          gradient: LinearGradient(colors: [
            MyTheme.gradientStart,
            MyTheme.gradientEnd,
          ]));
    }
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedContainer(
      duration: const Duration(seconds: 1),
      height: height,
      alignment: Alignment.center,
      child: ElevatedButton(
        onPressed: () {
          if (disabled) {
            return;
          }

          onPressed();
        },
        style: ButtonStyle(
          shape: MaterialStateProperty.all<RoundedRectangleBorder>(
            RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(height / 2),
            ),
          ),
          minimumSize: MaterialStateProperty.all(
              Size(MediaQuery.of(context).size.width, height)),
          backgroundColor: MaterialStateProperty.all(Colors.transparent),
          // elevation: MaterialStateProperty.all(3),
          shadowColor: MaterialStateProperty.all(Colors.transparent),
        ),
        child: text.text.color(Colors.white).make(),
      ),
      decoration: getBoxDecoration(),
    );
  }

  GradientButton(
      {required this.onPressed,
      this.text = '',
      this.disabled = false,
      this.height = 46});
}
